package com.uzhie.jt808.jt1078.entity;

import com.uzhie.jt808.JT808MsgBody;
import com.uzhie.jt808.msg.entity.BitConverter;
import com.uzhie.jt808.msg.entity.MyBuffer;

/**
 *
 * 8103 系统参数设置
 * Created by lilongfei on 2018/8/9.
 */
public class JT_8103_Catalog implements JT808MsgBody {

    /**
     * 参数ID
     */
    byte[] ID;
    /**
     * 消息体长度
     */
    int length;

    /**
     * 参数值
     */
    byte[] param;

    public byte[] getID() {
        return ID;
    }

    public void setID(byte[] ID) {
        this.ID = ID;
    }

    public int getLength() {
        return BitConverter.GetBytes(length)[3];
    }

    public void setLength(int length) {
        this.length = length;
    }

    public byte[] getParam() {
        return param;
    }

    public void setParam(byte[] param) {
        this.param = param;
    }

    @Override
    public byte[] WriteToBytes() {
        MyBuffer buffer = new MyBuffer();
        buffer.put(getID());
        buffer.put(BitConverter.GetBytes(length)[3]);
        buffer.put(getParam());
        return buffer.array();
    }

    @Override
    public void ReadFromBytes(byte[] body) {
        MyBuffer buffer = new MyBuffer(body);
        setID(buffer.gets(4));
        setLength(buffer.get());
        setParam(buffer.gets(getLength()));
 //       setParam(buffer.getString(getLength()));
    }

/*    @Override
    public String toString() {
        StringBuilder sBuilder = new StringBuilder();
        sBuilder.append(String.format(
                "参数ID：%1$s", "参数长度：%2$s", "参数值：%3$s"
                , BitConverter.ToUInt32(getID(),0),getLength(),getParam()));
        return sBuilder.toString();
    }*/
}
